home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Mac OS Development Toolkit / Automation Essentials 2.3.0 / Host Automation Folder / VU External Tool libs / VUAid.Lib < prev    next >
Encoding:
Text File  |  1998-03-19  |  25.1 KB  |  687 lines  |  [TEXT/MPS ]

  1. #########################################################################
  2. #########################################################################
  3. ##                     Copyright © Apple Computer, Inc. 1992-1997
  4. ##                                All rights reserved
  5. #########################################################################
  6. #########################################################################
  7. #    
  8. #    Library:        VUAid.lib
  9. #    
  10. #    Version:        2.1.4
  11. #    
  12. #    Description:
  13. #    
  14. #    Contains:
  15. #        VUAid()
  16. #        IsVUAidInstalled()
  17. #        VUAidReturnLongIntegers()
  18. #        
  19. #        launch_app()
  20. #        whichCheckSum()
  21. #        path()
  22. #        pathq()
  23. #        pathToList()
  24. #        open_by_path()
  25. #    
  26. #    History:
  27. #            Some of these tasks were originally found in 007, written by 
  28. #            EH and Alan Liu.  Some have had minor changes, many 
  29. #            have had major changes. Some still use the names of their 
  30. #            predecessors but are entirely rewritten.
  31. #        Date:        By:            Changes:
  32. #        05/01/92    Jason Marsh    Clouseau 1.0 creation
  33. #        02/19/94    SBR            Changed ControlPanels.lib to TargetControl.lib in Libraries.
  34. #        02/19/94    SBR            Moved tasks to TargetControl: InstallVUAid(), sys_vers(), 
  35. #                                sys7(), target_cpu(), CPUstic(), target_info()
  36. #        09/12/94    SBR            Changes for VUAid 2.1.
  37. #        09/04/95    SBR            Changes to VUAid().
  38. #        06/01/96    SBR/MSO        Updated copyright header
  39. #        09/27/96    BRL/MSO        Added SPEC exception handling
  40. #        12/03/96    Masa        changed call to abort_script(). Radar 1185040
  41. #        01/21/97    SBR            Deleted older exception code and comments.
  42. #
  43. #    Version      Date        Who        Comments
  44. #    =======    ========    ===        =================
  45. #    2.1.0    02/12/97    JAS        Added 'vers' resources to library.
  46. #                                These should always match tool version when tool is revved.
  47. #            03/20/97    SBR        IsVUAidInstalled() uses EnableProgramLinking().
  48. #    
  49. #########################################################################
  50. #########################################################################
  51.  
  52. Libraries 
  53.     "Clouseau.lib", 
  54.     "ExceptionHandling.lib", 
  55.     "Report.lib", 
  56.     "TargetControl.lib", 
  57.     "VUAid.tool";
  58.  
  59. #########################################################################
  60. #    task                    VUAid(command, parameterList, v_level)
  61. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  62. #    Description:    Invokes the VUAid 2.1 external tool and requests a service.
  63. #    Parameters:        command:        name of the service requested
  64. #                    parameterList:    list of all the parameters to send
  65. #                                        to the service
  66. #                    v_level:        verbosity level for log output
  67. #    Returns:        Result returned by external tool.
  68. #                        If no result is expected, and there were no errors,
  69. #                            we return true;
  70. #                        If an error occurred, we return undefined.
  71. #    Examples:        checkSum := VUAid("CompareWindowRect", {10,10,30,30});
  72. #    Assumptions:    VU 2.1, VUAid 2.1 resides on target machine
  73. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  74. #    History:
  75. #        12/23/92    Jon Marsh        Total rework for VUAid 2.0
  76. #        12/15/93    Jay Loucks        Convert parameterList to a list if
  77. #                                    it is not. Fixed Radar 1121052.
  78. #        02/09/94    SBR                Give non-list to VUAid directly.
  79. #        02/09/94    SBR                Calculate card(parameterList) once.
  80. #        02/09/94    SBR                Check first for no parameters (speed)
  81. #        09/04/95    SBR                Use VU 2.1 switch for various size parameter lists
  82. #########################################################################
  83. task    VUAid(command, parameterList := {}, v_level := 5)
  84. begin
  85.     RStatus("VUAid: requesting {command} service from VUAid",v_level);
  86.         
  87.     if IsVUAidInstalled()
  88.     begin
  89.         ####    SBR:    moved no parameters case out here for speed (13 of 30 services)
  90.         if parameterList = {}
  91.             result := VUAid2(command);
  92.             
  93.         ####    JDL:    convert to a list if it is not a list
  94.         ####    SBR:    move inside if IsVUAidInstalled() loop and give it to VUAid directly
  95.         else if TypeOf(parameterList) <> 'list'
  96.             result := VUAid2(command, parameterList);
  97.             
  98.         else 
  99.         begin
  100.             ####    SBR:    calculate card(parameterList) once
  101.             ####    SBR:    use switch statement
  102.             paramListCard := card(parameterList);
  103.             switch paramListCard
  104.             begin
  105.                 case 1:
  106.                     result := VUAid2(command,     parameterList[1]);
  107.                 case 2:
  108.                     result := VUAid2(command,     parameterList[1], parameterList[2]);
  109.                 case 3:
  110.                     result := VUAid2(command,     parameterList[1], parameterList[2], parameterList[3]);
  111.                 case 4:
  112.                     result := VUAid2(command,    parameterList[1], parameterList[2], parameterList[3], 
  113.                                                 parameterList[4]);
  114.                 case 5:
  115.                     result := VUAid2(command,    parameterList[1], parameterList[2], parameterList[3], 
  116.                                                 parameterList[4], parameterList[5]);
  117.                 case 6:
  118.                     result := VUAid2(command,    parameterList[1], parameterList[2], parameterList[3], 
  119.                                                 parameterList[4], parameterList[5], parameterList[6]);
  120.             end;
  121. #                if paramListCard = 1
  122. #                    result := VUAid2(command, parameterList[1]);
  123. #                else if paramListCard = 4
  124. #                    result := VUAid2(command, parameterList[1], parameterList[2], parameterList[3], parameterList[4]);
  125. #                else if paramListCard = 2
  126. #                    result := VUAid2(command, parameterList[1], parameterList[2]);
  127. #                else if paramListCard = 3
  128. #                    result := VUAid2(command, parameterList[1], parameterList[2], parameterList[3]);
  129. #                else if paramListCard = 5
  130. #                    result := VUAid2(command, parameterList[1], parameterList[2], parameterList[3], parameterList[4], parameterList[5]);
  131. #                else if paramListCard = 6
  132. #                    result := VUAid2(command, parameterList[1], parameterList[2], parameterList[3], parameterList[4], parameterList[5], parameterList[6]);
  133.         end;
  134.         
  135.         if command = "Quit"
  136.             global __gVUAid2Present := undefined;
  137.         if RXStatus(v_level)
  138.             println "VUAid tool returns: ", result, " for parameter list: ", parameterList;
  139.         if result[1] = 0
  140.             if IsUndefined(result[2])
  141.                 return true;
  142.             else return result[2];
  143.     end;
  144.     return undefined;
  145. end;
  146.  
  147. #########################################################################
  148. #    task                    IsVUAidInstalled(reInit, v_level)
  149. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  150. #    Description:    Determines if the VUAid 2.1 external tool is available
  151. #                    and launches and initializes if it isn't.
  152. #    Parameters:        reInit:        true to re-initialize the tool (use if we
  153. #                                restarted the machine but still think the
  154. #                                tool is running - ha, ha)
  155. #                    v_level:    verbosity level for log output
  156. #    Returns:        true if VUAid 2.1 is available,
  157. #                    false if the tool could not be found, launched or initialized.
  158. #    Examples:        IsVUAidInstalled(true);
  159. #    Assumptions:    VUAid 2.1
  160. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  161. #    History:
  162. #        8/5/91        EH        Creation as part of VUAidLib.vu for 007
  163. #        3/4/92        Jason Marsh        Incorporated into Clouseau.Lib
  164. #        12/23/92    Jonathan Marsh    Rewrote for VUAid 2.0
  165. #        02/15/94    SBR                Added section to turn on Program Linking
  166. #        02/15/94    SBR                Added check for -1224 or -1223 launch failures
  167. #        09/03/94    SBR                Added error handling for target access
  168. #        09/14/94    SBR                v_level at 5 to report VUAid still ready
  169. #        03/20/97    SBR                Changed v_level to 5 
  170. #        03/20/97    SBR                Uses EnableProgramLinking().
  171. #        05/29/97    SBR                Default v_level (1) for RError calls (was 2)
  172. #########################################################################
  173. task    IsVUAidInstalled(reInit := false, v_level := 5)
  174. begin
  175.     global __gVUAid2Present, g_VUAidReturnLongs;
  176.     
  177.     if isUndefined(__gVUAid2Present) or reInit
  178.     begin
  179.         VUAidWasInitialized := true;
  180.         test4VUAid := VUAid2("Initialize", true);
  181.         theScriptError := ScriptError();
  182.         __gVUAid2Present := (test4VUAid[1] = 0);
  183.         
  184.         if theScriptError = -1223
  185.         begin
  186.             RError('IsVUAidlnstalled: VUAid external tool not found or failed to launch.');
  187.             RError('IsVUAidlnstalled: Copy it to a hard disk and/or rebuild the desktop file.');
  188.         end;
  189.         else if theScriptError = -1224
  190.             RError('IsVUAidlnstalled: External tool launch failed. Is there enough memory?');
  191.         else if not __gVUAid2Present
  192.         begin
  193.             # Use the TargetControl.lib task to enable linking.
  194.             EnableProgramLinking(true,true);
  195.         end;
  196.         
  197.         test4VUAid := VUAid2("Initialize", true);    # Finally, retry VUAid
  198.         theScriptError := ScriptError();
  199.         __gVUAid2Present := (test4VUAid[1] = 0) and (theScriptError = 0);
  200.     end;
  201.     if __gVUAid2Present
  202.     begin
  203.         if isUndefined(g_VUAidReturnLongs)
  204.             rtnLongString := 'with default output types';
  205.         else 
  206.         begin
  207.             VUAid2('ReturnLongInts',g_VUAidReturnLongs);
  208.             rtnLongString := assoc(    g_VUAidReturnLongs, { {true,'to return long integers'},
  209.                                         {false,'to return longInt strings'}});
  210.         end;
  211.  
  212. #        09/14/94    SBR        report at v_level 5 unless VUAid was REALLY initialized
  213.         if VUAidWasInitialized
  214.             RStatus ("IsVUAidlnstalled: VUAid 2.1 was initialized {rtnLongString}.", v_level);
  215.         else 
  216.             RStatus ("IsVUAidlnstalled: VUAid 2.1 is ready {rtnLongString}.", 5);
  217.     end;
  218.     else 
  219.         RError ("IsVUAidlnstalled: VUAid 2.1 initialization failed!", 2);
  220.     return(__gVUAid2Present);
  221. end;
  222.  
  223.  
  224. #########################################################################
  225. #    task                    VUAidReturnLongIntegers(returnLongs)
  226. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  227. #    Description:    Sets up the global variable to store the g_VUAidReturnLongs
  228. #                    global. When IsVUAidInstalled() actually launches VUAid, it 
  229. #                    uses the 'ReturnLongInts' service to ensure the values are 
  230. #                    returned in the desired format.
  231. #                    Note:    VU 2.0.x will convert longs from external tools to 
  232. #                            strings, so this routine is useful only for a script 
  233. #                            running under VU 2.1.
  234. #    Parameters:        returnLongs: 
  235. #                        true: VUAid 2.1 returns long integers to VU
  236. #                        false: VUAid 2.1 returns longInt strings to VU
  237. #    Returns:        success: true
  238. #                    failure: false
  239. #    Examples:        VUAidReturnLongIntegers(true);
  240. #    Assumptions:    VU 2.1, VUAid 2.1
  241. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  242. #    History:
  243. #        09/11/94    SBR        Created 
  244. #        03/20/97    SBR        Changed v_level to 5 
  245. #########################################################################
  246. task VUAidReturnLongIntegers(returnLongs := true, v_level := 5) 
  247. begin
  248.     global g_VUAidReturnLongs, __gVUAid2Present;
  249.     
  250.     g_VUAidReturnLongs := not not returnLongs;    #coerce to Boolean type for assoc
  251.     RStatus("VUAidReturnLongIntegers({g_VUAidReturnLongs}).", v_level);
  252.  
  253.     if __gVUAid2Present
  254.     begin
  255.         theResult := VUAid2('ReturnLongInts',g_VUAidReturnLongs);
  256.         if theResult[1]
  257.         begin
  258.             RError("VUAidReturnLongIntegers: tool returned {theResult}.", 2);
  259.             return false;
  260.         end;
  261.     end;
  262.     return true;
  263. end;
  264.  
  265.  
  266. #########################################################################
  267. #    task            launch_app(appName, filesToOpen, exactNames, launchInForeground)
  268. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  269. #    Description:    Open an application, without knowing its location in
  270. #                    the Finder.  Open requested file(s) as well.
  271. #    Parameters:        None
  272. #    Returns:        Nothing
  273. #    Examples:        launch_app("TeachText", "ReadMe");
  274. #    Assumptions:    If there are multiple copies of an application you
  275. #                    will not know which one it will open.  The same is
  276. #                    true of multiple 'fileToOpen' names in different
  277. #                    folders.  The file will not necessarily be the one
  278. #                    in the same folder as the application, either.  This
  279. #                    is a powerful launch tool, but use it carefully.
  280. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  281. #    History:
  282. #        3/12/92        Jason Marsh        Created as part of VUAid.Lib
  283. #        12/23/92    Jon Marsh        Rewrote to call VUAid 2.0
  284. #        09/11/94    SBR    added exactNames, launchInForeground
  285. #########################################################################
  286. task    launch_app(    appName, filesToOpen := "", launchInForeground := true, 
  287.                     exactNames := true, v_level := 5 )
  288. begin
  289.     if filesToOpen = ""                                        # no file specified
  290.         filesToOpen := {};
  291.     else if typeOf(filesToOpen) <> 'list'                     # one file specified
  292.         filesToOpen := {filesToOpen};
  293.                                                         # else multiple files assumed
  294.     result :=  VUAid("Launch", {appName, filesToOpen, launchInForeground, exactNames}, v_level);
  295.  
  296.     if isUndefined(result)
  297.         return false;
  298.     
  299.     if launchInForeground
  300.     begin
  301.         if await_presence([application t:appName],120) 
  302.             return RStatus("launch_app: launched {appName} in the foreground",v_level);  #returns true always
  303.     end;
  304.     else 
  305.     begin
  306.         processMenu := _Match([menuItem t:"Hide {_match([application]).t}"]).m.o;
  307.         
  308.         if await_presence([menuItem t:appName m:processMenu],120) 
  309.             return RStatus("launch_app: launched {appName} in the background",v_level);  #returns true always
  310.     end;
  311.         
  312.     return false;
  313. end;
  314.  
  315.  
  316. #########################################################################
  317. #    task                    whichCheckSum(checkSumList, bitDepth, grays)
  318. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  319. #    Description:    Returns the checksum from the list based on current bit-depth
  320. #    Parameters:        checkSumList:    expected checksums, per bitdepth -
  321. #                        { 1bitcksum, 2bitcksum, 4bitcksum, 8bitcksum, 16bitcksum, 32bitcksum
  322. #                            [, grays2bitcksum, grays4bitcksum, grays8bitcksum]}
  323. #                        NOTE: greys values are optional, will assume values are the same for
  324. #                        grey and color if not present.
  325. #                    bitDepth: pass this in if you know it, as it will save execution time
  326. #                    greys: pass this in it you know it, as it will save execution time
  327. #    Returns:        Nothing
  328. #    Examples:        expected := whichCheckSum({'123','234','345','456','567'});
  329. #    Assumptions:    Uses VUAid to determine the current screen depth and grey setting
  330. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  331. # History:
  332. #        3/19/92        Jon Marsh        Created
  333. #        6/9/92        Jason Marsh        Updated for gray checksums
  334. #########################################################################
  335. task    whichCheckSum(checkSumList, bitdepth := -1, grays := -1)
  336. begin
  337.     if bitDepth = -1 
  338.         bitDepth := VUAid("GetDepth");
  339.     if grays = -1
  340.         grays := VUAid("GetGray");
  341.     if grays = 1 and card checkSumList > 6
  342.     begin
  343.         if bitDepth = 8
  344.             return checkSumList[9];
  345.         else if bitDepth = 4
  346.             return checkSumList[8];
  347.         else if bitDepth = 2
  348.             return checkSumList[7];
  349.     end;
  350.     else 
  351.     begin
  352.         if bitDepth = 8
  353.             return checkSumList[4];
  354.         else if bitDepth = 16
  355.             return checkSumList[5];
  356.         else if bitDepth = 32
  357.             return checkSumList[6];
  358.     end;
  359.  
  360.     if bitDepth = 1
  361.         return checkSumList[1];
  362.     else if bitDepth = 4
  363.         return checkSumList[3];
  364.     else if bitDepth = 2
  365.         return checkSumList[2];
  366.     return ("unknown bit-depth");
  367. end;
  368.  
  369.  
  370. #########################################################################
  371. #    task            FlashRect(pRect, pNumFlashes, pTimeInverted)
  372. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  373. #    Description:    Uses the VUAid InvertRect service to highlight a rectangle on the 
  374. #                    screen. This is useful for developing scripts.
  375. #    Parameters:        pRect:             Screen (global) rectangle
  376. #                    pNumFlashes:     number of times to flash
  377. #                    pTimeInverted:    milliseconds to stay in each state
  378. #    #    Returns:        Nothing
  379. #    Examples:        FlashRect((match [control o:34]).r, 500, 4);
  380. #    Assumptions:    VU 2.1 for milliseconds parameter to wait task.
  381. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  382. #    History:
  383. #        09/17/94    SBR    created
  384. #########################################################################
  385. task    FlashRect( pRect, pNumFlashes := 1, pTimeInverted := 500 )
  386. begin
  387.     for pNumFlashes := pNumFlashes to 1 step -1
  388.     begin
  389.         VUAid("InvertScreenRect", pRect);
  390.         wait(0,0,0,pTimeInverted);
  391.         VUAid("InvertScreenRect", pRect);
  392.         wait(0,0,0,pTimeInverted);
  393.     end;
  394. end;
  395.  
  396.  
  397. #########################################################################
  398. #    task                    pathToList(fullPathName)
  399. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  400. #    Description:    converts a pathname to a list of items
  401. #    Parameters:        fullPathName:  full path name of format "Item1:Item2"
  402. #    Returns:        List of items in the path name.  no Item will have a ":" in it.
  403. #    Examples:        pathList:= pathToList("Macintosh HD:Applications:TeachText");
  404. #    Assumptions:    None
  405. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  406. #    History:
  407. #        04/12/92    Jason Marsh        Created
  408. #########################################################################
  409. task    pathToList(fullPathName)
  410. begin
  411.     currentItem:= "";     #init variables
  412.     pathList := {};        
  413.     
  414.     for i:= 1 to card fullPathName
  415.     begin
  416.         temp := fullPathName[i];
  417.         if temp = ":"
  418.         begin
  419.             pathList := insert(currentItem, card pathList + 1, pathList);
  420.             currentItem := "";
  421.         end;
  422.         else 
  423.             CurrentItem := currentItem + temp;
  424.     end;
  425.     
  426.     if currentItem <> ""         #include the last item in case the  path name didn't end with ":"
  427.         pathList := insert(currentItem, card pathList + 1, pathList);
  428.     return pathList;
  429. end;
  430.  
  431.  
  432. #########################################################################
  433. #    task                    open_by_path(fullPathName, expectedDesc)
  434. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  435. #    Description:    Open a window from the full path name of the file
  436. #    Parameters:        fullPathName:  full path name of format "Item1:Item2"
  437. #                        NOTE: the path name is not the true 'system' path name,
  438. #                        but the apparent path name to the user.  So, desktop
  439. #                        items are simply one item: i.e. the path name to the
  440. #                        trash is simply "Trash", not "Internal:Trash" or 
  441. #                        "Internal:DeskTop:Trash"
  442. #                    expectedDesc: defaults to an open window of name "ItemN", but can be used
  443. #                        to check for the proper launch of an application, etc.
  444. #    Returns:        Nothing
  445. #    Examples:        ourFolder:= VUAid("FindFolder", {"font"}) + ":Times:Times";
  446. #                    open_by_path(ourFolder);
  447. #    Assumptions:    this routine inteligently checks to see what the orignal
  448. #                    open windows were, and leaves them open as it goes through
  449. #                    them
  450. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  451. #    History:
  452. #        04/12/92    Jason Marsh        Created
  453. #        11/09/93    Jay Loucks        added elipsis to select_menuItem() call
  454. #                                    to handle new exact match requirements
  455. #        09/27/96    BRL/MSO            Added SPEC exception handling
  456. #########################################################################
  457. task    open_by_path(fullPathName, expectedDesc := [])
  458. begin
  459.     rStatus("open_by_path: opening window " + fullPathName, 4);
  460.     pathList := pathToList(fullPathName);
  461.     if expectedDesc = []
  462.         expectedDesc := [window t:pathList[card pathList]];
  463.     try
  464.         match [window t:$oldWindows];
  465.     catch theError
  466.         ExceptionDispatcher(theError,,{"match 1 in open_by_path()", {fullPathName, expectedDesc}});
  467.     select_menuItem('About This Macintosh…');
  468.     type_keys({'latch', commandKey, 'latch', shiftKey, UpArrowKey});        #make the desktop active
  469.     vol:=pathList[1];
  470.     _Type ({vol});
  471.     
  472.     select_window("About This Macintosh");
  473.     type_keys({ 'down', commandKey, "w", "o", 'up', commandKey});            #opens the volume
  474.     
  475.     for i:= 2 to card pathList
  476.     begin
  477.         currentItem := pathList[i];
  478.         
  479.         type_Keys({currentItem, 'latch', commandKey, "i"});
  480.         currentItem := currentItem + " info";
  481.         if not await_presence([window t:currentItem],3,,,6)
  482.             return RIncomplete("Incomplete: open_by_path failed to open path: {fullPathName}",3);
  483.         key_eq("w");            #close 'info' window
  484.  
  485.         try
  486.             match [window t:?currentWindow];    
  487.         catch theError
  488.             ExceptionDispatcher(theError,,{"match 2 in open_by_path()", {fullPathName, expectedDesc}});
  489.         if isMember(currentWindow, oldWindows)
  490.             key_eq("o");                        #don't close the source window
  491.         else 
  492.             key_eq("o",5);                        #close the source window
  493.     end;
  494.         
  495.     if not await_presence(expectedDesc,3,,,6)
  496.         return RIncomplete("Incomplete: open_by_path failed to open path: {fullPathName}",3);
  497.             
  498.     return true;
  499. end;
  500.  
  501.  
  502. #########################################################################
  503. #    task                    path(pathType, leafitem)
  504. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  505. #    Description:    Provides a full HFS pathname based on the pathType parameter.
  506. #    Parameters:        pathType:                    returns a full pathname to:
  507. #                        (default)                    the top Finder window
  508. #                        'Top Window'                the top Finder window
  509. #                        'Boot Volume'                startup volume
  510. #                        'Blessed'                    currently active System folder
  511. #                        'Trash'                        Trash Folder on startup volume
  512. #                        'Desktop'                    Desktop Folder on startup volume
  513. #                        'Apple Menu Items'            The special System sub-folders…
  514. #                        'Control Panels'
  515. #                        'Extensions'
  516. #                        'Fonts'
  517. #                        'Preferences'    
  518. #                        'PrintMonitor Documents'    *** Not created on newly installed system
  519. #                        'StartupItems'
  520. #                        'Temporary Items'            *** Not created on newly installed system
  521. #                    leafitem: optional item within the folder specified by pathType
  522. #    Returns:        success: full pathname of the specified item
  523. #                    failure: false
  524. #    Examples:        VUAid("move", {path('Blessed', thing), path('Apple Menu Items')});
  525. #                    VUAid("delete", {path('Apple Menu Items', thing)});
  526. #    Assumptions:    To be nice, the script closes all the windows it opens
  527. #                    along the way, unless they were already open. At the very
  528. #                    end, it attempts to select the windows so that they end up
  529. #                    in the same order they started (unless one is covered and
  530. #                    can't be clicked).
  531. #                        New Path Manager uses FindFolder module for all folders
  532. #                    except Top Window, which still requires the old command
  533. #                    up-arrow method. This initPaths() version calls
  534. #                    vuAid('FindFolder macs') and exits the entire script if
  535. #                    an error occurs.
  536. #                        Will not restore ordinals of folders with the same name
  537. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  538. #    History:
  539. #        04/09/92    SBR    Created 
  540. #        05/11/92    SBR    Incorporated new FindFolder VUaid module
  541. #        09/27/96    BRL/MSO            Added SPEC exception handling
  542. #########################################################################
  543. task    path(pathType := 'Top Window', leafitem := '') begin
  544.     global gPaths, bootVolume, gPathBlessed, pathBootVolume;
  545.     
  546.     if IsUndefined(gPaths)
  547.         initPaths();
  548.     oldSpeed := TypeSpeed(50);
  549.     
  550.     if pathType = 'Top Window'
  551.     begin
  552.         rStatus('Getting full pathname to the top window.', 4);    
  553.         
  554.         if isUndefined(oldWindows)
  555.         begin
  556.             try
  557.                 match [window t:$oldWindows];
  558.             catch theError
  559.                 ExceptionDispatcher(theError,,{"match 1 in path", {pathType, leafitem}});
  560.         end;
  561.  
  562.         try
  563.             match [window t:?windowName o:1]!;
  564.         catch theError
  565.             ExceptionDispatcher(theError,,{"match 2 in path", {pathType, leafitem}});
  566.         if windowName = 'Desktop'
  567.             pathname := VUAid("FindFolder", {"desk"});
  568.         else 
  569.         begin
  570.             bootVolume := VUAid("FindFolder", {"boot"});
  571.             pathBootVolume := bootVolume + ':';
  572.         
  573.             pathname := '';
  574.                 
  575.             while (windowName <> 'Desktop')
  576.             begin
  577.                 previousName := windowName;
  578.                 pathname := windowName + ':' + pathname;
  579.                 
  580.                 if not(isMember(windowName, oldWindows))
  581.                     _PressKey ({optionKey});
  582.                 type_keys({'latch', commandKey, upArrowKey});
  583.                 _ReleaseKey ({optionKey});
  584.                 await_absence([window t:previousName o:1]);
  585.                 try
  586.                     match [window t:?windowName o:1]!;
  587.                 catch theError
  588.                     ExceptionDispatcher(theError,,{"match 3 in path", {pathType, leafitem}});
  589.             end;
  590.             
  591.             if previousName <> bootVolume
  592.             begin
  593.                 if previousName = 'Trash'
  594.                     pathname := pathBootVolume + pathname;
  595.                 else 
  596.                     pathname := pathBootVolume + 'Desktop Folder:' + pathname;
  597.             end;
  598.         end;
  599.         
  600.         rStatus('Restoring previous window arrangement.', 4);
  601.         numOldWinds := card(oldWindows);
  602.         await_presence([window t:oldWindows[numOldWinds]]);
  603.         for i := 0 to (numOldWinds-1)
  604.         begin
  605.             tempTitle := oldWindows[numOldWinds - i];
  606.             if tempTitle <> 'Desktop'
  607.                 select_window(tempTitle);
  608.             else 
  609.                 type_keys({'latch', commandKey, 'latch', shiftKey, upArrowKey});
  610.         end;
  611.         
  612.         rStatus('Finished getting full pathname to the top window.', 4);
  613.     end;
  614.     
  615.     else 
  616.     begin
  617.         PathList := {{'Boot Volume','boot'}, 
  618.             {'Blessed',"macs"},
  619.             {'Trash' ,"trsh"},
  620.             {'Desktop', "desk"},
  621.             {'Apple Menu Items', "amnu"},
  622.             {'Control Panels', "ctrl"},
  623.             {'Extensions', "extn"}, 
  624.             {'Fonts', "font"},
  625.             {'Preferences', "pref"}, 
  626.             {'PrintMonitor Documents', "prnt"},
  627.             {'Startup Items', "strt"},
  628.             {'Temporary Items', "temp"}};
  629.         
  630.         temp := assoc(pathType,PathList);
  631.         
  632.         if not temp 
  633.             RIncomplete('Path was given an undefined pathType: ' + pathType);
  634.         else 
  635.         begin
  636.             pathName := VUAid("FindFolder", {temp});
  637.             if IsUndefined(pathName)
  638.                 return RIncomplete("VUAid FindFolder returned an error");
  639.             if leafItem <> '' 
  640.                 pathName := pathName + ":";
  641.         end;
  642.     end;        
  643.  
  644.     TypeSpeed(oldSpeed);
  645.  
  646.     return pathname + leafItem;
  647. end;
  648.  
  649.  
  650. #########################################################################
  651. #    task                    initPaths(restoreWindows)
  652. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  653. #    Description:    Sets up the global variables necessary for path() to
  654. #                    operate. Usually not called by scripters, it gets
  655. #                    called by path() if gPaths is undefined.
  656. #    Parameters:        restoreWindows: caller puts a false here if it intends
  657. #                        to restore windows
  658. #    Returns:        success: a list of the currently open windows before initializing
  659. #                    failure: false
  660. #    Examples:        initPaths();
  661. #    Assumptions:    Does not work with international systems
  662. #                    Will not restore ordinals of folders with the same name
  663. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  664. #    History:
  665. #        04/09/92    SBR    Created 
  666. #        12/03/96    Masa            changed call to abort_script(). Radar 1185040
  667. #########################################################################
  668. task    initPaths(restoreWindows := true) begin
  669.     if IsUndefined(global gPathsOK)
  670.     begin
  671.         rStatus('Initializing the Path Manager.', 4);
  672.     
  673.         oldSpeed := TypeSpeed(50);
  674.         if not VUAid("FindFolder", {"macs"})
  675.         begin
  676.             rError("Fatal error: Path Manager startup failed. Check VUAid for FindFolder module?");
  677.             abort_script("initPaths: Path Manager startup failed. Check VUAid for FindFolder module?");
  678.         end;
  679.     
  680.         TypeSpeed(oldSpeed);
  681.         global gPathsOK := true;
  682.         rStatus('Finished initializing the Path Manager', 4);
  683.         return true;
  684.     end;
  685. end;
  686.  
  687.